﻿jQuery(document).ready(function () {
    var currentTime = new Date();
    var minimumDate = new Date(currentTime.getFullYear(), currentTime.getMonth(), currentTime.getDate());

    AttachDateRange('txtBeginDate', 'txtEndDate');
    jQuery('#txtBeginTime, #txtEndTime').timepicker({ showPeriod:true, showLeadingZero:false });

    jQuery('.titleHintBox').inputHintBox({ div: jQuery('#shiny_box'), div_sub: '.shiny_box_body', source: 'attr', attr: 'title', incrementLeft: 5 });

    initValidation();
    initCodeCampForm();

    document.onkeypress = stopRKey;
});

function initCodeCampForm() {
    jQuery('#txtMaximumCapacity').mask('?99999', { placeholder: ' ' });

    var acOptions = { serviceUrl: rolesHandler, minChars: 2 };
    jQuery('#txtRoleName').autocomplete(acOptions);
    jQuery('#txtWaitListRoleName').autocomplete(acOptions);
}

function validateCodeCamp() {
    var errCount = 0;
    errCount = errCount + requireField('txtTitle');
    errCount = errCount + requireField('txtDescription');
    errCount = errCount + requireField('txtBeginDate');
    errCount = errCount + requireField('txtBeginTime');
    errCount = errCount + requireField('txtEndDate');
    errCount = errCount + requireField('txtEndTime');
    errCount = errCount + requireField('txtRoleName');
    errCount = errCount + requireField('txtWaitListRoleName');
    errCount = errCount + requireField('txtMaximumCapacity');
    if (errCount > 0) {
        return false;
    } else {
        return true;
    }
}